package sample.magic_square_sol;

import java.util.Scanner;

public class MSMain
{
    private enum ParseState { NONE, N,  P_ROW, P_COL };
    
    private static ParseState parseState = ParseState.NONE;    
    
    private static final long NANOSEC_IN_1_MINUTE = 150000000000l;

    public static int dimen = 20;
    
    public static void msmain(boolean hasConstrain, int dimension, int[][] data, boolean[][] isFixed)
    {
        ProgOptions options = new ProgOptions();
        parseState = ParseState.N;
        Scanner input=new Scanner(System.in);

        //int n=input.nextInt();
        int n = dimension;
        dimen = dimension;

        //int constarint=input.nextInt();
        int constarint = hasConstrain ? 1: 0;
        if(constarint==1){
            options.constrained=true;
        }
        else{
            options.constrained=false;
        }
        options.n = n;
        options.m = (options.n*((options.n*options.n) + 1))/2;

        MagicSquareSolver solver =  new SimulatedAnnealingSolver(options);
        
        long startTime = System.nanoTime();
        
        // algorithm is allowed to run for 1 minute
        MagicSquareSolution bestSolution = solver.solve(NANOSEC_IN_1_MINUTE, data, isFixed);
        
        long elapsedTimeSec = (System.nanoTime() - startTime)/1000000000;
        
        System.out.println("Best solution found after " + elapsedTimeSec
                         + " seconds has fitness " + bestSolution.fitness + ":");
        
        HelperFunctions.outputSquare(bestSolution.square, options.n);
    }
}
